package com.meowcook.service.impl;

import com.meowcook.exception.AppException;
import com.meowcook.common.AppResult;
import com.meowcook.common.ResultCode;
import com.meowcook.dao.HealthInfoMapper;
import com.meowcook.mapper.HealthInfoPojoMapper;
import com.meowcook.pojo.dto.HealthInfoDTO;
import com.meowcook.pojo.po.HealthInfo;
import com.meowcook.service.IHealthInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 28792
 * Date: 2025-04-29
 * Time: 21:17
 */
@Slf4j
@Service
public class HealthInfoServiceImpl implements IHealthInfoService {

    @Resource
    private HealthInfoMapper healthInfoMapper;

    @Resource
    private HealthInfoPojoMapper healthInfoPojoMapper;

    @Override
    public void storeOne(HealthInfoDTO healthInfoDTO, Long userId) {
        // 数据转化
        HealthInfo healthInfo = healthInfoPojoMapper.toPO(healthInfoDTO);
        //设置userId
        healthInfo.setUserId(userId);
        // 创建时间
        Date date = new Date();
        healthInfo.setCreateTime(date);
        healthInfo.setUpdateTime(date);
        int row = healthInfoMapper.insertSelective(healthInfo);
        if (row != 1) {
            log.warn(ResultCode.ERROR_SERVICE.toString());
            throw new AppException(AppResult.fail(ResultCode.ERROR_SERVICE));
        }
    }
}
